Blockchain
ProvenAIBlockchainUtil
ProvenAIIssuer
The ProvenAIBlockchainUtil class is a utility class used to interact with specific smart contracts on the blockchain, including recording usage and retrieving smart contract data.
Attributes:
web3: Manages the connection to the Ethereum blockchain.credentials: Stores the Ethereum account private key used for signing transactions.contractAddress: The Ethereum address of the deployed smart contract.provenAIAgentUsageContract: Instance of the ProvenAIAgentUsage contract.counterContract: A smart contract handling counters.
Methods:
-
getEthereumPrivateKeyFromJWKExtracts and returns the Ethereum private key from a given JWK (JSON Web Key) string. -
getEthereumAddressFromPublicJWKExtracts the public key from a JWK string and returns the corresponding Ethereum address. -
getEthereumAddressFromDIDConverts a DID (Decentralized Identifier) to an Ethereum address by extracting and decoding the public key. -
recordDailyUsageRecords daily usage for a specific agent or account by submitting a Merkle Root hash to the blockchain. -
getDailyUsageRetrieves the daily usage data for a specified agent and date from the smart contract. incrementCounter, getCounterValue, setCounterValue -
isTransactionRegisteredChecks if a transaction with a given hash has been successfully registered on the blockchain.
MerkleTreeUtil
This class provides utility methods for working with Merkle Trees. It creates a Merkle Tree from a list of data, verifying the validity of proofs, and extracting proofs for specific data elements.
Methods:
-
createMerkleTreeCreates a Merkle Tree from a list of items. -
getProofRetrieves the proof for a specific item in the Merkle Tree. -
verifyProofVerifies whether a given item and proof are valid for the specified Merkle Root hash.
Model
This module provides two smart contract models generated by the Web3j library, representing contracts deployed on the Ethereum blockchain. They are Java representations of Ethereum smart contracts with methods for interacting with the blockchain.
Counter:
A smart contract that allows interaction with the contract methods such as:
getNumber(): Retrieves the number stored in the contract.increment(): Increments the stored number.setNumber: Sets a specific number. It extends Web3j's Contract class and provides various constructors for initializing the contract with credentials, transaction managers, and gas providers.
ProvenAIAgentUsage:
A contract designed to handle usage records of agents (e.g., AI agents) with functions like:
getDailyUsage(agent, date): Retrieves the usage data of an agent for a given date.recordDailyUsage(date, rootHash): Records the usage data for a given date.updateDailyUsageForAgent(agent, date, rootHash): Updates usage data for a specific agent on a specific date. It also tracks ownership and allows transferring ownership with the transferOwnership(newOwner) method.